package com.ninogame.state;

import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParserException;

import com.ninogame.BitmapFont;
import com.ninogame.GameLayer;
import com.ninogame.GameLib;
import com.ninogame.IConstant;
import com.ninogame.MazeEscape;
import com.ninogame.Map;
import com.ninogame.Sprite;
import com.ninogame.Actor.Creature;
import com.ninogame.Actor.Explorer;

import android.R.color;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Style;
import android.view.KeyEvent;


public class StateLogo extends MazeEscape implements IConstant {
	public static Bitmap logoBitmap = null;
	public static long timer = 0;
	public static int loadingStep = 0;	
	public static String sizePreFix = "";
	public static float scalex = SCREEN_WIDTH*1.0f/800;
	public static float scaley = SCREEN_HEIGHT*1.0f/1280;

	public static synchronized void SendMessage(int type) {

		switch (type) {
		case MESSAGE_CTOR:
			if (SCREEN_HEIGHT >= 1200) {
				sizePreFix = "1280x800";
			} else if (SCREEN_HEIGHT >= 1000) {
				sizePreFix = "1024x600";
			} else if (SCREEN_HEIGHT > 700) {
				sizePreFix = "800x480";
			} else if (SCREEN_HEIGHT > 440) {
				sizePreFix = "480x320";
			} else if (SCREEN_HEIGHT > 360) {
				sizePreFix = "400x240";
			} else {
				sizePreFix = "320x240";
			}
			
			logoBitmap = loadImageFromAsset("image/logo.png");
			loadingStep = 0;
			timer = System.currentTimeMillis();
			scalex = SCREEN_WIDTH*1.0f/800;
			scaley = SCREEN_HEIGHT*1.0f/1280;
			

			break;
		case MESSAGE_UPDATE:
			switch (loadingStep) {
			case 1:
			
				break;
			case 2:
				if (SCREEN_HEIGHT > 700) {
					if (MazeEscape.fontsmall_White == null)
						MazeEscape.fontsmall_White = new BitmapFont("font/white_24.spr", true);
					if (MazeEscape.fontsmall_Yellow == null)
						MazeEscape.fontsmall_Yellow = new BitmapFont("font/yellow_24.spr", true);
					if (MazeEscape.fontbig_White == null)
						MazeEscape.fontbig_White = new BitmapFont("font/white_36.spr", true);
					if (MazeEscape.fontbig_Yellow == null)
						MazeEscape.fontbig_Yellow = new BitmapFont("font/yellow_36.spr", true);
				} else if (SCREEN_HEIGHT > 300) {
					if (MazeEscape.fontsmall_White == null)
						MazeEscape.fontsmall_White = new BitmapFont("font/white_big_400x240.spr", true);
					if (MazeEscape.fontsmall_Yellow == null)
						MazeEscape.fontsmall_Yellow = new BitmapFont("font/yellow_big_400x240.spr", true);
					if (MazeEscape.fontbig_White == null)
						MazeEscape.fontbig_White = new BitmapFont("font/white_big_400x240.spr", true);
					if (MazeEscape.fontbig_Yellow == null)
						MazeEscape.fontbig_Yellow = new BitmapFont("font/yellow_big_400x240.spr", true);
				}
				break;
			case 3:

				break;
			case 4:

				break;
			case 5:
				if (StateMainMenu.splashBitmap == null)
					StateMainMenu.splashBitmap = loadImageFromAsset("image/splash.png");
				break;
			case 6:
				if (StateGameplay.spriteDPad == null)
				{
					float scalex = SCREEN_WIDTH*1.0f/800;
					float scaley = SCREEN_HEIGHT*1.0f/1280;
					StateGameplay.spriteDPad = new Sprite("sprite/ui/dpad.sprite",true,scalex,scalex);
				}
				if (StateGameplay.spriteWall == null)
					StateGameplay.spriteWall = new Sprite(
							"sprite/deco/wall.sprite", true);
				break;
			case 7:
				bitmapScreenBuffer = Bitmap.createBitmap(800, 1280,
						Config.ARGB_4444);
				canvasScreenBuffer = new Canvas(bitmapScreenBuffer);
				break;
			default:
				break;
			}
			loadingStep++;

			if ((System.currentTimeMillis() - timer > 3500) && loadingStep > 10) {
				changeState(STATE_MAINMENU);
			}
			break;
		case MESSAGE_PAINT:

			MazeEscape.mainPaint.setColor(Color.BLACK);
			MazeEscape.mainPaint.setStyle(Style.FILL);
			mainCanvas.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
					MazeEscape.mainPaint);
			MazeEscape.mainPaint.setColor(Color.WHITE);
			MazeEscape.mainPaint.setTextSize(20);
			// matrix.reset();
			// matrix.setScale(SCREEN_WIDTH*1f/1280, SCREEN_HEIGHT*1f/800);
			mainCanvas.drawBitmap(logoBitmap,
					(SCREEN_WIDTH - logoBitmap.getWidth()) / 2,
					(SCREEN_HEIGHT - logoBitmap.getHeight()) / 2 - 20,
					mainPaint);
			// mainCanvas.drawText(strString, 000, 100, mainPaint);

			break;
		case MESSAGE_DTOR:
			break;
		}
	}
}
